package com.ruoyi.machine.base.device.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.machine.base.device.domain.Device;
import com.ruoyi.machine.base.device.service.IDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备信息
 * 控制层
 * @author lsy
 */

@RestController
@RequestMapping("/machine/device")
@Api(value = "设备信息模块", tags = "设备信息接口")
public class DeviceController extends BaseController {

    @Autowired
    private IDeviceService deviceService;

    /**
     * 获取设备信息列表
     * @param device
     * @return
     */
    @ApiOperationSupport(includeParameters = {"Device.machineId", "Device.machineName"})
    @ApiOperation(value = "获取设备列表",notes = "查询所有设备列表信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Device device) {
        startPage();
        List<Device> deviceList = deviceService.selectDeviceList(device);
        return getDataTable(deviceList);
    }

    /**
     * 导出设备信息
     * @param device
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody Device device) {

        List<Device> deviceList = deviceService.selectDeviceList(device);

        ExcelUtil<Device> util = new ExcelUtil<>(Device.class);

        return util.exportExcel(deviceList, "设备信息数据");
    }

    /**
     * 新增设备
     * @param device
     * @return
     */
    @ApiOperation(value = "新增设备", notes = "新增设备信息")
    @ApiImplicitParam(name = "device", value = "新增设备信息(参数:machineId、procedureId、machineName、machineModel、machineType、machineSpecs、machineSize、machineWeight、machineManufacturer、departmentId、machineAddress、manufactureDate、machinePurchaseDate、machineStartDate、machineStaffId)", dataType = "Device")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody Device device) {
        return toAjax(deviceService.insertDevice(device));
    }

    /**
     * 修改设备信息
     * @param device
     * @return
     */
    @ApiOperation(value = "修改设备信息", notes = "修改设备信息")
    @ApiImplicitParam(name = "device", value = "修改设备信息(参数:procedureId、machineName、machineModel、machineType、machineSpecs、machineSize、machineWeight、machineManufacturer、departmentId、machineAddress、manufactureDate、machinePurchaseDate、machineStartDate、machineStaffId)", dataType = "Device")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody Device device) {
        return toAjax(deviceService.updateDevice(device));
    }

    /**
     * 删除设备信息
     * 仅修改删除标志位
     * @param device
     * @return
     */
    @ApiOperation(value = "删除设备信息", notes = "删除设备信息,仅删除标志位")
    @ApiImplicitParam(name = "device", value = "删除设备信息", dataType = "Device")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Device device) {
        return toAjax(deviceService.updateDeviceDeleteFlag(device));
    }
}
